package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
)

func openFile(fileName string) string {
	var str [1024]byte
	var fileStr string
	fileObj, err := os.Open("../public/index.html")
	if err != nil {
		fmt.Printf("open file, err: %v\n", err)
	}
	defer fileObj.Close()

	for {
		n, err := fileObj.Read(str[:])
		if err == io.EOF {
			break
		}
		if err != nil {
			fmt.Printf("err: %v\n", err)
		}
		fileStr += string(str[:n])
	}
	return fileStr
}
func fun(w http.ResponseWriter, r *http.Request) {
	str := openFile("../public/index.html")
	w.Write([]byte(str))
}

func main() {
	// listen.err := net.Listen("http", "127.0.0.1:8001")

	// http.HandleFunc("/posts/Go/15_socket/", fun)
	fmt.Println("server running ...")
	http.HandleFunc("/", fun)
	// http.ListenAndServe("127.0.0.1:8001", nil)
	http.ListenAndServe("192.168.31.105:8001", nil)
}
